<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>grand</title>
  </head>
  <body bgcolor="#FFFFFF">
    <center>Scilab Function</center>
    <div align="right">Last update : 11/04/2005</div>
    <p>
      <b>grand</b> -  Random number generator(s)   </p>
    <h3>
      <font color="blue">Calling Sequence</font>
    </h3>
    <dl>
      <dd>
        <tt>Y=grand(m, n, dist_type [,p1,...,pk])  </tt>
      </dd>
      <dd>
        <tt>Y=grand(X, dist_type [,p1,...,pk])  </tt>
      </dd>
      <dd>
        <tt>Y=grand(n, dist_type [,p1,...,pk])  </tt>
      </dd>
      <dd>
        <tt>S=grand(action [,q1,....,ql])  </tt>
      </dd>
    </dl>
    <h3>
      <font color="blue">Parameters</font>
    </h3>
    <ul>
      <li>
        <tt>
          <b>m, n</b>
        </tt>: integers, size of the wanted matrix <tt>
          <b>Y</b>
        </tt>
      </li>
      <li>
        <tt>
          <b>X</b>
        </tt>: a matrix whom only the dimensions (say <tt>
          <b>m x n</b>
        </tt>) are used</li>
      <li>
        <tt>
          <b>dist_type</b>
        </tt>: a string given the distribution which (independants) variates are to be 
     generated ('bin', 'nor', 'poi', etc ...)</li>
      <li>
        <tt>
          <b>p1, ..., pk</b>
        </tt>: the parameters (reals or integers) required to define completly the distribution 
    <tt>
          <b>dist_type</b>
        </tt>
      </li>
      <li>
        <tt>
          <b>Y</b>
        </tt>: the resulting <tt>
          <b>m x n</b>
        </tt> random matrix</li>
      <li>
        <tt>
          <b>action</b>
        </tt>: a string given the action onto the base generator(s) ('setgen' to change the current base 
     generator,  'getgen' to retrieve the current base generator name, 'getsd' to retrieve the 
     state (seeds) of the current base generator, etc ...)</li>
      <li>
        <tt>
          <b>q1, ..., ql</b>
        </tt>: the parameters (generally one string) needed to define the action</li>
      <li>
        <tt>
          <b>S</b>
        </tt>: output of the action (generaly a string or a real column vector)</li>
    </ul>
    <h3>
      <font color="blue">Description</font>
    </h3>
    <p>
     This function may be used to generate random numbers from various distributions. In this 
     case you must apply one of the 
     <tt>
        <b>three first forms</b>
      </tt> of the possible calling sequences to get an <tt>
        <b>m x n</b>
      </tt> matrix. 
     The two firsts are equivalent if <tt>
        <b>X</b>
      </tt> is a <tt>
        <b>m x n</b>
      </tt> matrix, 
     and the third form corresponds to 'multivalued' distributions (e.g. multinomial, multivariate
     gaussian, etc...) where a sample is a column vector (says of dim <tt>
        <b>m</b>
      </tt>)
     and you get then <tt>
        <b>n</b>
      </tt> such random vectors (as an <tt>
        <b> m x n</b>
      </tt> matrix). 
     <tt>
        <b>The last form</b>
      </tt> is used to undertake various manipulations onto the base generators
     like changing the base generator (since v 2.7 you may choose between several base generators), 
     changing or retrieving its internal state (seeds), etc ... These base generators give random
     integers following a uniform distribution on a large integer interval (lgi), all the others 
     distributions being gotten from it (in general via a scheme lgi -&gt; U([0,1)) -&gt; wanted distribution).
  </p>
    <h3>
      <font color="blue">Getting random numbers from a given distribution</font>
    </h3>
    <dl>
      <dd>
        <li>
          <b>
            <font color="maroon">beta</font>
          </b>: <tt>
            <b>Y=grand(m,n,'bet',A,B)</b>
          </tt> generates random variates from 
     the beta distribution with parameters <tt>
            <b>A</b>
          </tt> and <tt>
            <b>B</b>
          </tt>. 
     The density of the beta is  (<tt>
            <b>0 &lt; x &lt; 1</b>
          </tt>) :<pre>
          A-1    B-1
         x   (1-x)   / beta(A,B) 
        </pre>
          <tt>
            <b>A</b>
          </tt> and <tt>
            <b>B</b>
          </tt> must be reals &gt;<tt>
            <b>10^(-37)</b>
          </tt>.
     Related function(s) : <a href="cdfbet.htm">
            <tt>
              <b>cdfbet</b>
            </tt>
          </a>.
        </li>
        <li>
          <b>
            <font color="maroon">binomial</font>
          </b>
   : <tt>
            <b>Y=grand(m,n,'bin',N,p)</b>
          </tt>  generates random variates from the binomial 
     distribution with parameters <tt>
            <b>N</b>
          </tt> (positive integer) and <tt>
            <b>p</b>
          </tt>
     (real in [0,1]) : number of successes in <tt>
            <b>N</b>
          </tt> independant 
     Bernouilli trials with probability <tt>
            <b>p</b>
          </tt> of success. 
     Related function(s) : <a href="../elementary/binomial.htm">
            <tt>
              <b>binomial</b>
            </tt>
          </a>, <a href="cdfbin.htm">
            <tt>
              <b>cdfbin</b>
            </tt>
          </a>.
       </li>
        <li>
          <b>
            <font color="maroon">negative binomial</font>
          </b>
   : <tt>
            <b>Y=grand(m,n,'nbn',N,p)</b>
          </tt> generates random variates from the negative binomial 
     distribution with parameters <tt>
            <b>N</b>
          </tt> (positive integer) and <tt>
            <b>p</b>
          </tt> (real 
     in (0,1)) : number of failures occurring before <tt>
            <b>N</b>
          </tt> successes 
     in independant Bernouilli trials with probability <tt>
            <b>p</b>
          </tt> of success.
     Related function(s) : <a href="cdfnbn.htm">
            <tt>
              <b>cdfnbn</b>
            </tt>
          </a>.
  </li>
        <li>
          <b>
            <font color="maroon">chisquare</font>
          </b>
   : <tt>
            <b>Y=grand(m,n,'chi', Df)</b>
          </tt> generates random variates from the chisquare distribution 
     with <tt>
            <b>Df</b>
          </tt> (real &gt; 0.0) degrees of freedom. 
     Related function(s) : <a href="cdfchi.htm">
            <tt>
              <b>cdfchi</b>
            </tt>
          </a>.  
  </li>
        <li>
          <b>
            <font color="maroon">non central chisquare</font>
          </b>
   : <tt>
            <b>Y=grand(m,n,'nch',Df,Xnon)</b>
          </tt> generates random variates from the non central chisquare
     distribution with <tt>
            <b>Df</b>
          </tt> degrees of freedom (real &gt;= 1.0) 
     and noncentrality parameter <tt>
            <b>Xnonc</b>
          </tt> (real &gt;= 0.0).
     Related function(s) : <a href="cdfchn.htm">
            <tt>
              <b>cdfchn</b>
            </tt>
          </a>.
  </li>
        <li>
          <b>
            <font color="maroon">exponential</font>
          </b>: <tt>
            <b>Y=grand(m,n,'exp',Av)</b>
          </tt> generates random variates from the exponential
     distribution with mean <tt>
            <b>Av</b>
          </tt> (real &gt;= 0.0).</li>
        <li>
          <b>
            <font color="maroon">F variance ratio</font>
          </b>
   : <tt>
            <b>Y=grand(m,n,'f',Dfn,Dfd)</b>
          </tt> generates random variates from the F 
     (variance ratio) distribution with <tt>
            <b>Dfn</b>
          </tt> (real &gt; 0.0)
     degrees of freedom in the numerator and <tt>
            <b>Dfd</b>
          </tt> (real &gt; 0.0) 
     degrees of freedom in the denominator. Related function(s) : <a href="cdff.htm">
            <tt>
              <b>cdff</b>
            </tt>
          </a>.
  </li>
        <li>
          <b>
            <font color="maroon">non central F variance ratio</font>
          </b>
   : <tt>
            <b>Y=grand(m,n,'nf',Dfn,Dfd,Xnon)</b>
          </tt> generates random variates from the noncentral 
     F (variance ratio)  distribution with <tt>
            <b>Dfn</b>
          </tt> (real &gt;= 1) degrees of freedom 
     in the numerator, and <tt>
            <b>Dfd</b>
          </tt> (real &gt; 0) degrees of freedom in the denominator, 
     and noncentrality parameter <tt>
            <b>Xnonc</b>
          </tt> (real &gt;= 0). 
      Related function(s) : <a href="cdffnc.htm">
            <tt>
              <b>cdffnc</b>
            </tt>
          </a>.
  </li>
        <li>
          <b>
            <font color="maroon">gamma</font>
          </b>: <tt>
            <b>Y=grand(m,n,'gam',shape,scale)</b>
          </tt> generates random variates from the gamma 
     distribution with parameters <tt>
            <b>shape</b>
          </tt> (real &gt; 0) and <tt>
            <b>scale</b>
          </tt> 
      (real &gt; 0). The density of the gamma is :<pre>
               shape  (shape-1)   -scale x
          scale       x          e          /  gamma(shape) 
        </pre>
     Related function(s) : <a href="../elementary/gamma.htm">
            <tt>
              <b>gamma</b>
            </tt>
          </a>, <a href="cdfgam.htm">
            <tt>
              <b>cdfgam</b>
            </tt>
          </a>.
  </li>
        <li>
          <b>
            <font color="maroon">Gauss Laplace (normal)</font>
          </b>
   : <tt>
            <b>Y=grand(m,n,'nor',Av,Sd)</b>
          </tt> generates random variates from the normal 
     distribution with mean <tt>
            <b>Av</b>
          </tt> (real)  and standard deviation <tt>
            <b>Sd</b>
          </tt>
     (real &gt;= 0). Related function(s) : <a href="cdfnor.htm">
            <tt>
              <b>cdfnor</b>
            </tt>
          </a>.
  </li>
        <li>
          <b>
            <font color="maroon">multivariate gaussian (multivariate normal)</font>
          </b>: <tt>
            <b>Y=grand(n,'mn',Mean,Cov)</b>
          </tt> generates  <tt>
            <b>n</b>
          </tt> multivariate normal random variates ; 
     <tt>
            <b>Mean</b>
          </tt> must be a <tt>
            <b>m x 1</b>
          </tt> matrix and <tt>
            <b>Cov</b>
          </tt> a  <tt>
            <b>m x m</b>
          </tt> 
     symetric positive definite matrix  (<tt>
            <b>Y</b>
          </tt> is then a  <tt>
            <b>m x n</b>
          </tt> matrix).</li>
        <li>
          <b>
            <font color="maroon">geometric</font>
          </b>: <tt>
            <b>Y=grand(m,n,'geom', p)</b>
          </tt> generates random variates from the geometric
     distribution with parameter <tt>
            <b>p</b>
          </tt> : number of Bernouilli trials (with 
     probability succes of <tt>
            <b>p</b>
          </tt>) until a succes is met. <tt>
            <b>p</b>
          </tt> must 
     be in <tt>
            <b>[pmin,1]</b>
          </tt> (with <tt>
            <b>pmin = 1.3 10^(-307)</b>
          </tt>).</li>
        <li>
          <b>
            <font color="maroon">markov</font>
          </b>
   : <tt>
            <b>Y=grand(n,'markov',P,x0)</b>
          </tt> generate <tt>
            <b>n</b>
          </tt> successive states of a Markov chain 
     described  by the transition matrix <tt>
            <b>P</b>
          </tt>. Initial state is  given by 
     <tt>
            <b>x0</b>
          </tt>. If <tt>
            <b>x0</b>
          </tt> is a matrix of size <tt>
            <b>m=size(x0,'*')</b>
          </tt> 
     then <tt>
            <b>Y</b>
          </tt> is a matrix of size <tt>
            <b>m x n</b>
          </tt>. <tt>
            <b>Y(i,:)</b>
          </tt> is the sample 
     path  obtained from initial state <tt>
            <b>x0(i)</b>
          </tt>.
  </li>
        <li>
          <b>
            <font color="maroon">multinomial</font>
          </b>
   : <tt>
            <b>Y=grand(n,'mul',nb,P)</b>
          </tt> generates <tt>
            <b>n</b>
          </tt> observations from the Multinomial 
     distribution :  class <tt>
            <b>nb</b>
          </tt> events in <tt>
            <b>m</b>
          </tt> categories (put <tt>
            <b>nb</b>
          </tt>
     "balls" in <tt>
            <b>m</b>
          </tt> "boxes"). <tt>
            <b>P(i)</b>
          </tt> is the probability 
     that an event will be classified into category i. <tt>
            <b>P</b>
          </tt> the vector of probabilities
     is of size  <tt>
            <b>m-1</b>
          </tt> (the probability of category <tt>
            <b>m</b>
          </tt> being <tt>
            <b>1-sum(P)</b>
          </tt>).
     <tt>
            <b>Y</b>
          </tt> is of size <tt>
            <b>m x n</b>
          </tt>, each column <tt>
            <b>Y(:,j)</b>
          </tt> being an observation 
     from multinomial distribution and <tt>
            <b>Y(i,j)</b>
          </tt> the number of events falling in category 
     <tt>
            <b>i</b>
          </tt> (for the <tt>
            <b>j</b>
          </tt> th observation) (<tt>
            <b>sum(Y(:,j)) = nb</b>
          </tt>).
  </li>
        <li>
          <b>
            <font color="maroon">Poisson</font>
          </b>: <tt>
            <b>Y=grand(m,n,'poi',mu)</b>
          </tt> generates random variates from the Poisson 
     distribution with mean <tt>
            <b>mu (real &gt;= 0.0)</b>
          </tt>.</li>
        <li>
          <b>
            <font color="maroon">random permutations</font>
          </b>: <tt>
            <b>Y=grand(n,'prm',vect)</b>
          </tt> generate <tt>
            <b>n</b>
          </tt> random permutations of the
     column vector (<tt>
            <b>m x 1</b>
          </tt>) <tt>
            <b>vect</b>
          </tt>.</li>
        <li>
          <b>
            <font color="maroon">uniform (def)</font>
          </b>: <tt>
            <b>Y=grand(m,n,'def')</b>
          </tt> generates random variates from the uniform 
     distribution over <tt>
            <b>[0,1)</b>
          </tt> (1 is never return).</li>
        <li>
          <b>
            <font color="maroon">uniform (unf)</font>
          </b>: <tt>
            <b>Y=grand(m,n,'unf',Low,High)</b>
          </tt> generates random reals uniformly distributed 
   in <tt>
            <b>[Low, High)</b>
          </tt>.</li>
        <li>
          <b>
            <font color="maroon">uniform (uin)</font>
          </b>: <tt>
            <b>Y=grand(m,n,'uin',Low,High)</b>
          </tt> generates random integers uniformly 
     distributed between <tt>
            <b>Low</b>
          </tt> and <tt>
            <b>High</b>
          </tt> (included). <tt>
            <b>High</b>
          </tt>
     and <tt>
            <b>Low</b>
          </tt> must be integers such that <tt>
            <b>(High-Low+1) &lt; 2,147,483,561</b>
          </tt>.</li>
        <li>
          <b>
            <font color="maroon">uniform (lgi)</font>
          </b>: <tt>
            <b>Y=grand(m,n,'lgi')</b>
          </tt> returns the basic output of the current generator : random integers  
     following a uniform distribution over :<dd>
            <li>
              <b>
                <font color="maroon"></font>
              </b>
              <p>
                <tt>
                  <b>[0, 2^32 - 1]</b>
                </tt> for mt, kiss and fsultra</p>
            </li>
            <li>
              <b>
                <font color="maroon"></font>
              </b>
              <p>
                <tt>
                  <b>[0, 2147483561]</b>
                </tt> for clcg2</p>
            </li>
            <li>
              <b>
                <font color="maroon"></font>
              </b>
              <p>
                <tt>
                  <b>[0, 2^31 - 2]</b>
                </tt> for clcg4</p>
            </li>
            <li>
              <b>
                <font color="maroon"></font>
              </b>
              <p>
                <tt>
                  <b>[0, 2^31 - 1]</b>
                </tt> for urand.</p>
            </li>
          </dd>
        </li>
      </dd>
    </dl>
    <h3>
      <font color="blue">Set/get the current generator and its state</font>
    </h3>
    <dl>
      <p> Since Scilab-2.7 you have the possibility to choose between different base 
      generators (which give random integers following the 'lgi' distribution, the others 
      being gotten from it) :
    </p>
      <dd>
        <li>
          <b>
            <font color="maroon">mt</font>
          </b>: the Mersenne-Twister of M. Matsumoto and T. Nishimura, period about <tt>
            <b>2^19937</b>
          </tt>, 
         state given by an array of <tt>
            <b>624</b>
          </tt> integers (plus an index onto this array); this  
         is the default generator.</li>
        <li>
          <b>
            <font color="maroon">kiss</font>
          </b>: The Keep It Simple Stupid of G. Marsaglia,  period about <tt>
            <b>2^123</b>
          </tt>,
         state given by <tt>
            <b>4</b>
          </tt> integers.</li>
        <li>
          <b>
            <font color="maroon">clcg2</font>
          </b>: a Combined 2 Linear Congruential Generator of P. L'Ecuyer,
         period about <tt>
            <b>2^61</b>
          </tt>, state given by <tt>
            <b>2</b>
          </tt> integers ; this was 
         the only generator previously used by grand (but slightly modified)</li>
        <li>
          <b>
            <font color="maroon">clcg4</font>
          </b>: a Combined 4 Linear Congruential Generator of P. L'Ecuyer,
         period about <tt>
            <b>2^121</b>
          </tt>, state given by 4 integers ; this one is 
         splitted in <tt>
            <b>101</b>
          </tt> different virtual (non over-lapping) generators 
         which may be useful for different tasks (see 'Actions specific to clcg4' and
         'Test example for clcg4').</li>
        <li>
          <b>
            <font color="maroon">urand</font>
          </b>: the generator used by the scilab function <a href="../elementary/rand.htm">
            <tt>
              <b>rand</b>
            </tt>
          </a>, state
         given by <tt>
            <b>1</b>
          </tt> integer, period of <tt>
            <b>2^31</b>
          </tt> (based  on  theory  
         and suggestions  given  in  d.e. knuth (1969),  vol  2. State). This
         is the faster of this list but a little outdated (don't use it for
         serious simulations).</li>
        <li>
          <b>
            <font color="maroon">fsultra</font>
          </b>: a Subtract-with-Borrow generator mixing with a congruential
	 generator of Arif Zaman and George Marsaglia, period more than <tt>
            <b>10^356</b>
          </tt>,
         state given by an array of 37 integers (plus an index onto this array, a flag (0 or 1)
         and another integer).</li>
      </dd>
      <p>The differents actions common to all the generators, are:
    </p>
      <dd>
        <li>
          <b>
            <font color="maroon">action= 'getgen'</font>
          </b>: <tt>
            <b>S=grand('getgen')</b>
          </tt> returns the current base generator ( <tt>
            <b>S</b>
          </tt> is
     a string among 'mt', 'kiss', 'clcg2', 'clcg4', 'urand', 'fsultra'.</li>
        <li>
          <b>
            <font color="maroon">action= 'setgen'</font>
          </b>: <tt>
            <b>grand('setgen',gen)</b>
          </tt> sets the current base generator to be <tt>
            <b>gen</b>
          </tt>
     a string among 'mt', 'kiss', 'clcg2', 'clcg4', 'urand', 'fsultra' (notes that this call 
     returns the new current generator, ie gen).</li>
        <li>
          <b>
            <font color="maroon">action= 'getsd'</font>
          </b>: <tt>
            <b>S=grand('getsd')</b>
          </tt> gets the current state (the current seeds) of the current base
     generator ; <tt>
            <b>S</b>
          </tt> is given as a column vector (of integers) of dimension <tt>
            <b>625</b>
          </tt> 
     for mt (the first being an index in <tt>
            <b>[1,624]</b>
          </tt>), <tt>
            <b>4</b>
          </tt> for kiss, <tt>
            <b>2</b>
          </tt> 
     for clcg2,  <tt>
            <b>40</b>
          </tt> for fsultra, <tt>
            <b>4</b>
          </tt> for clcg4 
     (for this last one you get the current state of the current virtual generator) and <tt>
            <b>1</b>
          </tt> 
     for urand.</li>
        <li>
          <b>
            <font color="maroon">action= 'setsd'</font>
          </b>: <tt>
            <b>grand('setsd',S), grand('setsd',s1[,s2,s3,s4])</b>
          </tt> sets the state of the current 
     base generator (the new seeds) :<dd>
            <li>
              <b>
                <font color="maroon">for mt</font>
              </b>: <tt>
                <b>S</b>
              </tt> is a vector of integers of dim <tt>
                <b>625</b>
              </tt> (the first component is an index
       and must be in <tt>
                <b>[1,624]</b>
              </tt>, the <tt>
                <b>624</b>
              </tt> last ones must be in 
       <tt>
                <b>[0,2^32[</b>
              </tt>) (but must not be all zeros) ; a simpler initialisation may be done 
       with only one integer <tt>
                <b>s1</b>
              </tt> (<tt>
                <b>s1</b>
              </tt> must be in <tt>
                <b>[0,2^32[</b>
              </tt>) ;</li>
            <li>
              <b>
                <font color="maroon">for kiss</font>
              </b>: <tt>
                <b>4</b>
              </tt> integers <tt>
                <b>s1,s2, s3,s4</b>
              </tt> in <tt>
                <b>[0,2^32[</b>
              </tt> must be provided ;</li>
            <li>
              <b>
                <font color="maroon">for clcg2</font>
              </b>: <tt>
                <b>2</b>
              </tt> integers <tt>
                <b>s1</b>
              </tt> in <tt>
                <b>[1,2147483562]</b>
              </tt> and <tt>
                <b>s2</b>
              </tt> 
       in  <tt>
                <b>[1,2147483398]</b>
              </tt> must be given ;</li>
            <li>
              <b>
                <font color="maroon">for clcg4</font>
              </b>: <tt>
                <b>4</b>
              </tt> integers <tt>
                <b>s1</b>
              </tt> in <tt>
                <b>[1,2147483646]</b>
              </tt>, <tt>
                <b>s2</b>
              </tt> 
       in <tt>
                <b>[1,2147483542]</b>
              </tt>, <tt>
                <b>s3</b>
              </tt> in <tt>
                <b>[1,2147483422]</b>
              </tt>, 
       <tt>
                <b>s4</b>
              </tt> in  <tt>
                <b>[1,2147483322]</b>
              </tt> are required ;
       <tt>
                <b>CAUTION</b>
              </tt> : with clcg4 you set the seeds of the current virtual
       generator but you may lost the synchronisation between this one
       and the others virtuals generators (ie the sequence generated
       is not warranty to be non over-lapping with a sequence generated
       by another virtual generator)=&gt; use instead the 'setall' option.
    </li>
            <li>
              <b>
                <font color="maroon">for urand</font>
              </b>: <tt>
                <b>1</b>
              </tt> integer <tt>
                <b>s1</b>
              </tt> in  <tt>
                <b>[0,2^31</b>
              </tt>[ must be given.</li>
            <li>
              <b>
                <font color="maroon">for fsultra</font>
              </b>:  <tt>
                <b>S</b>
              </tt> is a vector of integers of dim <tt>
                <b>40</b>
              </tt> (the first component 
       is an index and must be in <tt>
                <b>[0,37]</b>
              </tt>, the 2d component is a flag (0 or 1), the 3d
       an integer in [1,2^32[ and the 37 others integers in [0,2^32[) ; a simpler (and recommanded) 
       initialisation may be done with two integers <tt>
                <b>s1</b>
              </tt> and <tt>
                <b>s2</b>
              </tt> in 
       <tt>
                <b>[0,2^32[</b>
              </tt>.</li>
          </dd>
        </li>
        <li>
          <b>
            <font color="maroon">action= 'phr2sd'</font>
          </b>: <tt>
            <b>Sd=grand('phr2sd', phrase)</b>
          </tt> given a <tt>
            <b>phrase</b>
          </tt> (character string) generates 
     a <tt>
            <b>1 x 2</b>
          </tt> vector <tt>
            <b>Sd</b>
          </tt> which may be used as seeds to change the state of a 
     base generator (initialy suited for clcg2).</li>
      </dd>
    </dl>
    <h3>
      <font color="blue">Options specific to clcg4</font>
    </h3>
    <dl>
      <p>
    The clcg4 generator may be used as the others generators but it offers the advantage 
    to be splitted in several (<tt>
          <b>101</b>
        </tt>) virtual generators with non over-lapping 
    sequences (when you use a classic generator you may change the initial state (seeds) 
    in order to get another sequence but you are not warranty to get a complete  different one). 
    Each virtual generator corresponds to a sequence of <tt>
          <b>2^72</b>
        </tt> values which is 
    further split into <tt>
          <b>V=2^31</b>
        </tt> segments (or blocks) of length <tt>
          <b>W=2^41</b>
        </tt>.
    For a given virtual generator you have the possibility to return at the beginning of the 
    sequence or at the beginning of the current segment or to go directly at the next segment. 
    You may also change the initial state (seed) of the generator <tt>
          <b>0</b>
        </tt> with the 
    'setall' option which then change also the initial state of the other virtual generators 
    so as to get synchronisation (ie in function of the new initial state of gen <tt>
          <b>0</b>
        </tt> 
    the initial state of gen <tt>
          <b>1..100</b>
        </tt> are recomputed so as to get <tt>
          <b>101</b>
        </tt> 
    non over-lapping sequences.   
  </p>
      <dd>
        <li>
          <b>
            <font color="maroon">action= 'setcgn'</font>
          </b>: <tt>
            <b>grand('setcgn',G)</b>
          </tt> sets the current virtual generator for clcg4 (when clcg4
     is set, this is the virtual (clcg4) generator number <tt>
            <b>G</b>
          </tt> which is used);  the virtual clcg4 
     generators are numbered from <tt>
            <b>0,1,..,100</b>
          </tt> (and so <tt>
            <b>G</b>
          </tt> must be an integer 
     in  <tt>
            <b>[0,100]</b>
          </tt>) ; by default the current virtual generator is <tt>
            <b>0</b>
          </tt>.</li>
        <li>
          <b>
            <font color="maroon">action= 'getcgn'</font>
          </b>: <tt>
            <b>S=grand('getcgn')</b>
          </tt> returns the number of the current virtual clcg4 generator.</li>
        <li>
          <b>
            <font color="maroon">action= 'initgn'</font>
          </b>: <tt>
            <b>grand('initgn',I)</b>
          </tt> reinitializes the state of the current virtual generator<dd>
            <li>
              <b>
                <font color="maroon">I = -1</font>
              </b>: sets the state to its initial seed</li>
            <li>
              <b>
                <font color="maroon">I = 0</font>
              </b>: sets the state to its last (previous) seed (i.e. to the beginning  of the current segment)</li>
            <li>
              <b>
                <font color="maroon">I = 1</font>
              </b>: sets the state to a new seed <tt>
                <b>W</b>
              </tt> values from its last seed (i.e. to the beginning 
        of the next segment) and resets the current segment parameters.</li>
          </dd>
        </li>
        <li>
          <b>
            <font color="maroon">action= 'setall'</font>
          </b>: <tt>
            <b>grand('setall',s1,s2,s3,s4)</b>
          </tt> sets the initial state of generator <tt>
            <b>0</b>
          </tt> 
     to <tt>
            <b>s1,s2,s3,s4</b>
          </tt>. The initial seeds of the other generators are set accordingly 
     to have synchronisation. For constraints on <tt>
            <b>s1, s2, s3, s4</b>
          </tt> see the 'setsd' action.</li>
        <li>
          <b>
            <font color="maroon">action= 'advnst'</font>
          </b>: <tt>
            <b>grand('advnst',K)</b>
          </tt> advances the state of the current generator by <tt>
            <b>2^K</b>
          </tt> values 
     and  resets the initial seed to that value.</li>
      </dd>
    </dl>
    <h3>
      <font color="blue">Test example for clcg4</font>
    </h3>
    <dl>
      <p>
    An example of  the  need of the splitting capabilities of clcg4 is as  follows. 
    Two statistical techniques are being compared on  data of  different sizes. The first 
    technique uses   bootstrapping  and is   thought to   be  as accurate using less data   
    than the second method   which  employs only brute force.  For the first method, a data
    set of size uniformly distributed between 25 and 50 will be generated.  Then the data set  
    of the specified size will be generated and analyzed.  The second method will  choose a 
    data set size between 100 and 200, generate the data  and analyze it.  This process will 
    be repeated 1000 times.  For  variance reduction, we  want the  random numbers  used in the 
    two methods to be the  same for each of  the 1000 comparisons.  But method two will  use more
    random  numbers than   method one and  without this package, synchronization might be difficult.  
    With clcg4, it is a snap.  Use generator 0 to obtain  the sample size for  method one and 
    generator 1  to obtain the  data.  Then reset the state to the beginning  of the current  block
    and do the same  for the second method.  This assures that the initial data  for method two is 
    that used by  method  one.  When both  have concluded,  advance the block for both generators.</p>
    </dl>
    <h3>
      <font color="blue">See Also</font>
    </h3>
    <p>
      <a href="../elementary/rand.htm">
        <tt>
          <b>rand</b>
        </tt>
      </a>,&nbsp;&nbsp;</p>
    <h3>
      <font color="blue">Authors</font>
    </h3>
    <dl>
      <dd>
        <b>randlib</b>
     The codes to generate sequences following other distributions than def, unf, lgi,  uin and geom are
     from "Library of Fortran Routines for Random Number  Generation", by Barry W. Brown 
     and James Lovato, Department of Biomathematics, The University of Texas, Houston.  
  </dd>
      <dd>
        <b>mt</b>
     The code is the mt19937int.c by M. Matsumoto and  T. Nishimura, "Mersenne Twister: 
     A 623-dimensionally equidistributed  uniform pseudorandom number generator", 
     ACM Trans. on Modeling and  Computer Simulation Vol. 8, No. 1, January, pp.3-30 1998.
  </dd>
      <dd>
        <b>kiss</b>
     The code was given by G. Marsaglia at the end of a thread concerning RNG in C in several 
     newsgroups (whom sci.math.num-analysis) "My offer of  RNG's for C was an invitation 
     to dance..." only kiss have been included in Scilab (kiss is made of a combinaison of 
     severals others which are not visible at the scilab level).
  </dd>
      <dd>
        <b>clcg2</b>
     The method is from P. L'Ecuyer but the C code is provided at the Luc  Devroye home page 
     (http://cgm.cs.mcgill.ca/~luc/rng.html).
  </dd>
      <dd>
        <b>clcg4</b>
     The code is from P. L'Ecuyer and Terry H.Andres and provided at the P. L'Ecuyer
     home page ( http://www.iro.umontreal.ca/~lecuyer/papers.html) A paper is also provided 
     and this new package is the logical successor of an old 's one from : P.  L'Ecuyer
     and S. Cote.   Implementing a Random   Number Package with Splitting Facilities.  ACM Transactions 
     on Mathematical  Software 17:1,pp 98-111.
  </dd>
      <dd>
        <b>fsultra</b>
     code from Arif Zaman (arif@stat.fsu.edu) and George Marsaglia (geo@stat.fsu.edu)
  </dd>
      <dd>
        <b>scilab packaging</b>
     By Jean-Philippe Chancelier and Bruno Pincon  
  </dd>
    </dl>
  </body>
</html>
